from selenium.webdriver.common.by import By
from base.Base import Base
import os
import time


class Page(Base):
    name_loc = (By.NAME, 'email')
    pwd_loc = (By.NAME, 'password')
    deng_loc = (By.ID, 'dologin')
    frame_loc = (By.XPATH, '/html/body/div[3]/div[3]/div[1]/div/div[3]/div[1]/div[2]/iframe')

    def login_frame(self):
        self.switch_to_frame(0)

    def login_name(self, test):
        self.send_keys(self.name_loc, test)

    def login_pwd(self, pwd):
        self.send_keys(self.pwd_loc, pwd)

    def login_deng(self):
        self.click(self.deng_loc)

    def login_clear(self):
        self.clear(self.name_loc)

    def login_go(self, name, pwd):
        self.open_url(os.getenv('url'))
        print("打开网址")
        time.sleep(2)
        self.login_frame()
        print("进入frame框架")
        time.sleep(2)
        self.login_clear()
        time.sleep(2)
        self.login_name(name)
        self.login_pwd(pwd)
        print("输入账号密码")
        time.sleep(3)
        self.login_deng()
        print("点击登录")
        time.sleep(5)
        self.switch_file()
        print("退出框架")

